/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.CapEntityManager.teste;

import br.com.CapEntityManager.Pessoa5;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author egberto
 */
public class TestePersist {
    
    public static void main(String args[]){
        
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("default");
        EntityManager manager = factory.createEntityManager();
        
        //abrindo a transacao
        manager.getTransaction().begin();
        
        //objeto no estado new
        Pessoa5 p = new Pessoa5();
        p.setNome("Jose da Silva");
        
        //objeto no estado managed
        manager.persist(p);
        
        //sincronizando e confirmando a transacao
        manager.getTransaction().commit();
        
        System.out.println("Pessoa Id: " + p.getId());
        
        manager.close();
        factory.close();
        
    }
    
}
